<?php namespace App\Http\Controllers\user\search;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;
use Input;
use App\Models\Projects;
use App\Models\Devices;
use App\Models\Technologies;
use App\Models\News;
use DB;
use App\Models\Domains;
use App\Models\Techs;
use App\Models\Users;
use App\Models\AssociationBase;
use App\Models\DevicetechProviderBase;
use App\Models\EnterpriceEnergysaverBase;
use App\Models\EnterpricePowerusersBase;
use App\Models\GovernmentBase;
use App\Models\ThirdpartyBase;
use App\Models\UserRoles;
use App\Models\SearchMid;
use App\Models\SearchAll;


use Redirect;
use Illuminate\Pagination\LengthAwarePaginator;
use Landish\Pagination\Pagination as BootstrapPresenter;

class SearchController extends Controller {

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function index()
	{
		//
	}


	public function Search()
	{
		$type = Input::get("type");
		$keyWord = Input::get("keyWord");
		$keyArr = explode(' ', $keyWord);
		$temp = null;
		$energy = null;
		$saver = null;
		$third = null;
		$devicetech = null;
		$gov = null;
		$ass = null;
		$blade;
		$numPerPage = 24;
		if(!$keyWord){
			return ;
		}

		switch ($type)
		{
			case 0:
				$energy = EnterpricePowerusersBase::select("company_name",'uid','description', "id")->get()->toArray();
				$saver = EnterpriceEnergysaverBase::select("company_name",'uid','description', "id")->get()->toArray();
				$devicetech = DevicetechProviderBase::select("company_name",'uid','description', "id")->get()->toArray();
				$third = ThirdpartyBase::select("company_name",'uid','description', "id")->get()->toArray();
				$ass = AssociationBase::select("company_name",'uid','description', "id")->get()->toArray();
				$gov = GovernmentBase::select("company_name",'uid','description', "id")->get()->toArray();
				$project = Projects::select("name",'uid','description', "id")->get()->toArray();
				$tech = Technologies::select("tech_name",'uid','description', "id")->get()->toArray();
				$device = Devices::select("name",'uid','description', "id")->get()->toArray();

				foreach ($energy as $key => $value) {
					$model = SearchAll::where("uid", $value['uid'])->where("type", 0);
					if($model->count()){
						$model->update(["name"=>$value['company_name'], "description" => $value['description'], "uid"=>$value['uid'], "pid"=>$value['id'], "type"=>0 ]);
					}else{
						SearchAll::create(["name"=>$value['company_name'], "description" => $value['description'], "uid"=>$value['uid'], "pid"=>$value['id'], "type"=>0 ]);
					}
				}

				foreach ($saver as $key => $value) {
					$model = SearchAll::where("uid", $value['uid'])->where("type", 1);
					if($model->count()){
						$model->update(["name"=>$value['company_name'], "description" => $value['description'], "uid"=>$value['uid'], "pid"=>$value['id'], "type"=>1 ]);
					}else{
						SearchAll::create(["name"=>$value['company_name'], "description" => $value['description'], "uid"=>$value['uid'], "pid"=>$value['id'], "type"=>1 ]);
					}
				}

				foreach ($devicetech as $key => $value) {
					$model = SearchAll::where("uid", $value['uid'])->where("type", 2);
					if($model->count()){
						$model->update(["name"=>$value['company_name'], "description" => $value['description'], "uid"=>$value['uid'], "pid"=>$value['id'], "type"=>2 ]);
					}else{
						SearchAll::create(["name"=>$value['company_name'], "description" => $value['description'], "uid"=>$value['uid'], "pid"=>$value['id'], "type"=>2 ]);
					}
				}

				foreach ($third as $key => $value) {
					$model = SearchAll::where("uid", $value['uid'])->where("type", 3);
					if($model->count()){
						$model->update(["name"=>$value['company_name'], "description" => $value['description'], "uid"=>$value['uid'], "pid"=>$value['id'], "type"=>3 ]);
					}else{
						SearchAll::create(["name"=>$value['company_name'], "description" => $value['description'], "uid"=>$value['uid'], "pid"=>$value['id'], "type"=>3 ]);
					}
				}

				foreach ($ass as $key => $value) {
					$model = SearchAll::where("uid", $value['uid'])->where("type", 4);
					if($model->count()){
						$model->update(["name"=>$value['company_name'], "description" => $value['description'], "uid"=>$value['uid'], "pid"=>$value['id'], "type"=>4 ]);
					}else{
						SearchAll::create(["name"=>$value['company_name'], "description" => $value['description'], "uid"=>$value['uid'], "pid"=>$value['id'], "type"=>4 ]);
					}
				}

				foreach ($gov as $key => $value) {
					$model = SearchAll::where("uid", $value['uid'])->where("type", 5);
					if($model->count()){
						$model->update(["name"=>$value['company_name'], "description" => $value['description'], "uid"=>$value['uid'], "pid"=>$value['id'], "type"=>5 ]);
					}else{
						SearchAll::create(["name"=>$value['company_name'], "description" => $value['description'], "uid"=>$value['uid'], "pid"=>$value['id'], "type"=>5 ]);
					}
				}

				foreach ($project as $key => $value) {
					$model = SearchAll::where("uid", $value['uid'])->where("type", 6)->where("pid", $value['id']);
					if($model->count()){
						$model->update(["name"=>$value['name'], "description" => $value['description'], "uid"=>$value['uid'], "pid"=>$value['id'], "type"=>6 ]);
					}else{
						SearchAll::create(["name"=>$value['name'], "description" => $value['description'], "uid"=>$value['uid'], "pid"=>$value['id'], "type"=>6 ]);
					}
				}

				foreach ($tech as $key => $value) {
					$model = SearchAll::where("uid", $value['uid'])->where("type", 7)->where("pid", $value['id']);
					if($model->count()){
						$model->update(["name"=>$value['tech_name'], "description" => $value['description'], "uid"=>$value['uid'], "pid"=>$value['id'], "type"=>7 ]);
					}else{
						SearchAll::create(["name"=>$value['tech_name'], "description" => $value['description'], "uid"=>$value['uid'], "pid"=>$value['id'], "type"=>7 ]);
					}
				}

				foreach ($device as $key => $value) {
					$model = SearchAll::where("uid", $value['uid'])->where("type", 8)->where("pid", $value['id']);
					if($model->count()){
						$model->update(["name"=>$value['name'], "description" => $value['description'], "uid"=>$value['uid'], "pid"=>$value['id'], "type"=>8 ]);
					}else{
						SearchAll::create(["name"=>$value['name'], "description" => $value['description'], "uid"=>$value['uid'], "pid"=>$value['id'], "type"=>8 ]);
					}
				}

				foreach ($keyArr as $key => $value) {
					if(is_null($temp)){
						$temp = SearchAll::where("name", "like", "%".$value."%")->orWhere(function($query) use ($value){
							$query->orWhere("description", "like", "%".$value."%");
						});
					}else{
						$temp->where(function($query) use($value){
							$query->orWhere("name", "like", "%".$value."%")->orWhere("description", "like", "%".$value."%");
						});
					}
				}
				$temp = $temp->get();
				foreach ($temp as $key => $value) {
					switch ($value['type']) {
						case 0:
							$value->load("energy");
							$value['userData'] = $value['energy'];
							unset($value['energy']);
							break;
						case 1:
							$value->load("saver");
							$value['userData'] = $value['saver'];
							unset($value['saver']);
							break;
						case 2:
							$value->load("devicetech");
							$value['userData'] = $value['devicetech'];
							unset($value['devicetech']);
							break;
						case 3:
							$value->load("third");
							$value['userData'] = $value['third'];
							unset($value['third']);
							break;
						case 4:
							$value->load("ass");
							$value['userData'] = $value['ass'];
							unset($value['ass']);
							break;
						case 5:
							$value->load("gov");
							$value['userData'] = $value['gov'];
							unset($value['gov']);
							break;
						case 6:
							$value->load("project");
							break;
						case 7:
							$value->load("tech");
							break;
						case 8:
							$value->load("device");
							break;
						default:
							# code...
							break;
					}
				}
				// return $temp;

				return view('user.search.all', ["data" => $temp])->withIsProject(true)->withIsIndustry(true);

// ->withPresenter($presenter)
				break;
			case 1:
				foreach ($keyArr as $key => $value) {
					if(is_null($temp))
					{
						$temp = Projects::with(["projectDomain", "projectDomain.domain", "projectDomain.domain.parent", "projectTech", "projectTech.tech", "investmentType", "mainBody", "mainBody.mainBody", "technologies", "technologies.technology", "devices", "devices.device"])->where(function($query) use ($value){
							$query->where("name", "like", "%".$value."%");
							$query->orWhere("description", "like", "%".$value."%");
						});
					}
					else
					{
						$temp->where(function($query) use ($value){
							$query->orWhere("name", "like", "%".$value."%")->orWhere("description", "like", "%".$value."%");
						});
					}
				}
						$projects = $temp;
						if(Input::has("aid")){
							$projects->where(function($query){
								$query->whereIn("id", DB::table("project_domain")->whereIn("cate_id", DB::table("domains")->where("parent_id", Input::get("aid"))->lists("id"))->lists("project_id"))->orWhereIn("id", DB::table("project_domain")->where("cate_id", Input::get("aid"))->lists("project_id"));
							});
						}
						if(Input::has("cid"))
						{
							$projects->where(function($query){
								$query->whereIn("id", DB::table("project_domain")->where("cate_id", Input::get("cid"))->lists("project_id"));
							});
						}
						if(Input::has("tid"))
						{
							$projects->where(function($query){
								$query->whereIn("id", DB::table("project_tech")->where("cate_id", Input::get("tid"))->lists("project_id"));
							});
						}

						$count = $projects->count();
						$curPage = (int)Input::get("page", 1);
						$p = new LengthAwarePaginator($projects, $count, $numPerPage, $curPage);
						$p->setPath("");
				        $presenter = new BootstrapPresenter($p);

						$domains = Domains::with(["children" => function($query){
							$query->where("parent_id", Input::get("aid", 1));
						}])->where("parent_id", 0)->get()->toArray();
						$techs = Techs::all();

						$projects = $projects->orderBy("id", "desc")->skip(($curPage - 1) * $numPerPage)->take($numPerPage)->get()->toArray();

						$recProject = Projects::with(["projectDomain", "projectDomain.domain", "projectDomain.domain.parent", "projectTech", "projectTech.tech", "investmentType", "mainBody", "mainBody.mainBody", "technologies", "technologies.technology", "devices", "devices.device"])->where("is_rec", 1)->skip(($curPage - 1) * 5)->take(5)->get()->toArray();

						$bottomNumPerPage = 6;
						$bottomProject = Projects::with(["projectDomain", "projectDomain.domain", "projectDomain.domain.parent", "projectTech", "projectTech.tech", "investmentType", "mainBody", "mainBody.mainBody", "technologies", "technologies.technology", "devices", "devices.device"])->where("is_rec", 1)->skip(($curPage - 1) * $bottomNumPerPage)->take(6)->get()->toArray();
						$bottomDevice = Devices::where("is_rec", 1)->skip(($curPage - 1) * $bottomNumPerPage)->take(6)->get()->toArray();
						$bottomTech = Technologies::where("is_rec", 1)->skip(($curPage - 1) * $bottomNumPerPage)->take(6)->get()->toArray();

						$queryStr = "";
						foreach (Input::all() as $key => $value)
						{
							$queryStr .= $key . "=" . $value . "&";
						}
						$params = ["projects" => $projects, "count" => $count, "domains" => $domains, "techs" => $techs, "recommand" => $recProject, "bottomProject" => $bottomProject, "bottomDevice" => $bottomDevice, "bottomTech" => $bottomTech, "bottomTech" => $bottomTech, "curQuery" => $queryStr];

						if(Input::has("aid")){
							$firstLevel = Domains::where("id", Input::get("aid"));
							if($firstLevel->count()){
								$params["firstLevel"] = $firstLevel->get()[0]["cate_name"];
							}
						}

						if(Input::has("cid")){
							$secondLevel = Domains::where("id", Input::get("cid"));
							if($secondLevel->count()){
								$params["secondLevel"] = $secondLevel->get()[0]["cate_name"];
							}
						}

						if(Input::has("tid")){
							$thirdLevel = Techs::where("id", Input::get("tid"));
							if($thirdLevel->count())
							{
								$params["thirdLevel"] = $thirdLevel->get()[0]["cate_name"];
							}
						}

						return view('user.search.project', $params)->withPresenter($presenter)->withIsProject(true)->withIsIndustry(true);
				break;
			case 2:
				foreach ($keyArr as $key => $value) {
					if(is_null($temp))
					{
						$temp = Devices::where("name", "like", "%".$value."%")->where(function($query) use ($value){
							$query->orWhere("description", "like", "%".$value."%");
						});
					}
					else
					{
						$temp->where(function($query) use ($value){
							$query->orWhere("name", "like", "%".$value."%")->orWhere("description", "like", "%".$value."%");
						});
					}
				}
				$devices = $temp;
						if(Input::has("aid")){
							$devices->where(function($query){
								$query->whereIn("id", DB::table("device_domain")->whereIn("cate_id", DB::table("domains")->where("parent_id", Input::get("aid"))->lists("id"))->lists("device_id"))->orWhereIn("id", DB::table("device_domain")->where("cate_id", Input::get("aid"))->lists("device_id"));
							});
						}

						if(Input::has("cid"))
						{
							$devices->where(function($query){
								$query->whereIn("id", DB::table("device_domain")->where("cate_id", Input::get("cid"))->lists("device_id"));
							});
						}

						if(Input::has("tid"))
						{
							$devices->where(function($query){
								$query->whereIn("id", DB::table("device_tech")->where("cate_id", Input::get("tid"))->lists("device_id"));
							});
						}

						$count = $devices->count();

						$curPage = (int)Input::get("page", 1);
						$p = new LengthAwarePaginator($devices, $count, $numPerPage, $curPage);
						$p->setPath("");
				        $presenter = new BootstrapPresenter($p);

						$domains = Domains::with(["children" => function($query){
							$query->where("parent_id", Input::get("aid", 1));
						}])->where("parent_id", 0)->get()->toArray();
						$techs = Techs::all();

						$devices = $devices->skip(($curPage - 1) * $numPerPage)->take($numPerPage)->get()->toArray();

						$recDevices = Devices::where("is_rec", 1)->skip(($curPage - 1) * 5)->take(5)->get()->toArray();

						$bottomNumPerPage = 6;
						$bottomProject = Projects::with(["projectDomain", "projectDomain.domain", "projectDomain.domain.parent", "projectTech", "projectTech.tech", "investmentType", "mainBody", "mainBody.mainBody", "technologies", "technologies.technology", "devices", "devices.device"])->where("is_rec", 1)->skip(($curPage - 1) * $bottomNumPerPage)->take(6)->get();
						$bottomDevice = Devices::where("is_rec", 1)->skip(($curPage - 1) * $bottomNumPerPage)->take(6)->get();
						$bottomTech = Technologies::where("is_rec", 1)->skip(($curPage - 1) * $bottomNumPerPage)->take(6)->get();

						$queryStr = "";
						foreach (Input::all() as $key => $value)
						{
							$queryStr .= $key . "=" . $value . "&";
						}

						$params = ["devices" => $devices, "count" => $count, "domains" => $domains, "techs" => $techs, "recommand" => $recDevices, "bottomProject" => $bottomProject, "bottomDevice" => $bottomDevice, "bottomTech" => $bottomTech, "bottomTech" => $bottomTech, "curQuery" => $queryStr];

						if(Input::has("aid")){
							$firstLevel = Domains::where("id", Input::get("aid"));
							if($firstLevel->count()){
								$params["firstLevel"] = $firstLevel->get()[0]["cate_name"];
							}
						}

						if(Input::has("cid")){
							$secondLevel = Domains::where("id", Input::get("cid"));
							if($secondLevel->count()){
								$params["secondLevel"] = $secondLevel->get()[0]["cate_name"];
							}
						}

						if(Input::has("tid")){
							$thirdLevel = Techs::where("id", Input::get("tid"));
							if($thirdLevel->count())
							{
								$params["thirdLevel"] = $thirdLevel->get()[0]["cate_name"];
							}
						}

						return view('user.search.device', $params)->withPresenter($presenter)->withIsDevice(true)->withIsIndustry(true);



				break;
			case 3:
				foreach ($keyArr as $key => $value) {
					if(is_null($temp))
					{
						$temp = Technologies::where("tech_name", "like", "%".$value."%")->where(function($query) use ($value){
							$query->orWhere("description", "like", "%".$value."%");
						});
					}
					else
					{
						$temp->where(function($query) use ($value){
							$query->orWhere("tech_name", "like", "%".$value."%")->orWhere("description", "like", "%".$value."%");
						});
					}
				}
				$techsList = $temp;
						if(Input::has("aid")){
							$techsList->where(function($query){
								$query->whereIn("id", DB::table("tech_domain")->whereIn("cate_id", DB::table("domains")->where("parent_id", Input::get("aid"))->lists("id"))->lists("tech_id"))->orWhereIn("id", DB::table("tech_domain")->where("cate_id", Input::get("aid"))->lists("tech_id"));
							});
						}

						if(Input::has("cid"))
						{
							$techsList->where(function($query){
								$query->whereIn("id", DB::table("tech_domain")->where("cate_id", Input::get("cid"))->lists("tech_id"));
							});
						}

						if(Input::has("tid"))
						{
							$techsList->where(function($query){
								$query->whereIn("id", DB::table("tech_tech")->where("cate_id", Input::get("tid"))->lists("tech_id"));
							});
						}
						$count = $techsList->count();
						$curPage = (int)Input::get("page", 1);
						$p = new LengthAwarePaginator($techsList, $count, $numPerPage, $curPage);
						$p->setPath("");
				        $presenter = new BootstrapPresenter($p);

						$domains = Domains::with(["children" => function($query){
							$query->where("parent_id", Input::get("aid", 1));
						}])->where("parent_id", 0)->get()->toArray();
						$techs = Techs::all();

						$techsList = $techsList->skip(($curPage - 1) * $numPerPage)->take($numPerPage)->get();

						$recTechs = Technologies::where("is_rec", 1)->skip(($curPage - 1) * 5)->take(5)->get();

						$bottomNumPerPage = 6;
						$bottomProject = Projects::with(["projectDomain", "projectDomain.domain", "projectDomain.domain.parent", "projectTech", "projectTech.tech", "investmentType"])->where("is_rec", 1)->skip(($curPage - 1) * $bottomNumPerPage)->take(6)->get();
						$bottomDevice = Devices::where("is_rec", 1)->skip(($curPage - 1) * $bottomNumPerPage)->take(6)->get();
						$bottomTech = Technologies::where("is_rec", 1)->skip(($curPage - 1) * $bottomNumPerPage)->take(6)->get();

						$queryStr = "";
						foreach (Input::all() as $key => $value)
						{
							$queryStr .= $key . "=" . $value . "&";
						}

						$params = ["techsList" => $techsList, "count" => $count, "domains" => $domains, "techs" => $techs, "recommand" => $recTechs, "bottomProject" => $bottomProject, "bottomDevice" => $bottomDevice, "bottomTech" => $bottomTech, "bottomTech" => $bottomTech, "curQuery" => $queryStr];

						if(Input::has("aid")){
							$firstLevel = Domains::where("id", Input::get("aid"));
							if($firstLevel->count()){
								$params["firstLevel"] = $firstLevel->get()[0]["cate_name"];
							}
						}

						if(Input::has("cid")){
							$secondLevel = Domains::where("id", Input::get("cid"));
							if($secondLevel->count()){
								$params["secondLevel"] = $secondLevel->get()[0]["cate_name"];
							}
						}

						if(Input::has("tid")){
							$thirdLevel = Techs::where("id", Input::get("tid"));
							if($thirdLevel->count())
							{
								$params["thirdLevel"] = $thirdLevel->get()[0]["cate_name"];
							}
						}

						return view('user.search.tech', $params)->withPresenter($presenter)->withIsTech(true)->withIsIndustry(true);
				break;
			case 4:



				$energy = EnterpricePowerusersBase::select("company_name",'uid','description')->get()->toArray();
				$saver = EnterpriceEnergysaverBase::select("company_name",'uid','description')->get()->toArray();
				$device = DevicetechProviderBase::select("company_name",'uid','description')->get()->toArray();
				$third = ThirdpartyBase::select("company_name",'uid','description')->get()->toArray();
				$ass = AssociationBase::select("company_name",'uid','description')->get()->toArray();
				$gov = GovernmentBase::select("company_name",'uid','description')->get()->toArray();
				$energyCount 	= count($energy);
				$saverCount 	= count($saver);
				$deviceCount 	= count($device);
				$thirdCount 	= count($third);
				$assCount 		= count($ass);
				$govCount 		= count($gov);


				$merge = array_merge($energy, $saver, $device, $third, $ass, $gov);
				foreach ($merge as $key => $value) {
					$model = SearchMid::where("uid", $value['uid']);
					if($model->count()){
						$model->update($value);
					}else{
						if($key < $energyCount){
							$value["role_id"] = env("ENERGY");
						}elseif($key < $energyCount + $saverCount){
							$value["role_id"] = env("SAVER");
						}elseif($key < $deviceCount + $energyCount + $saverCount){
							$value["role_id"] = env("DEVICE_TECH");
						}elseif($key < $thirdCount + $deviceCount + $energyCount + $saverCount){
							$value["role_id"] = env("THIRD");
						}elseif($key < $assCount + $thirdCount + $deviceCount + $energyCount + $saverCount){
							$value["role_id"] = env("ASSOCIATION");
						}else{
							$value["role_id"] = env("GOVERNMENT");
						}

						SearchMid::create($value);
					}
				}

				foreach ($keyArr as $key => $value) {
					if(is_null($temp)){
						$temp = SearchMid::with(['users'])->where(function($query) use ($value){
							$query->where("company_name", "like", "%".$value."%")->orWhere("description", "like", "%".$value."%");
						});
					}else{
						$temp->where(function($query) use ($value){
							$query->orWhere("company_name", "like", "%".$value."%")->orWhere("description", "like", "%".$value."%");
						});
					}
				}
				if(Input::has("gid")){
					$temp->where("role_id", Input::get("gid"));
				}
						$count = $temp->count();

						$curPage = (int)Input::get("page", 1);
						$p = new LengthAwarePaginator($temp, $count, $numPerPage, $curPage);
						$p->setPath("");
				        $presenter = new BootstrapPresenter($p);

						$temp = $temp->skip(($curPage - 1) * $numPerPage)->take($numPerPage)->get();

				 foreach ($temp as $key => $value) {
				 	switch ($value['users']['role_id']) {
				 		case env("ENERGY"):
				 			$value->load("users.poweruser");
				 			$value['userData'] = $value['users']['poweruser'];
				 			unset($value['users']['poweruser']);
				 			break;
				 		case env("SAVER"):
				 			$value->load("users.energysaver");
				 			$value['userData'] = $value['users']['energysaver'];
				 			unset($value['users']['energysaver']);
				 			break;
				 		case env("DEVICE_TECH"):
				 			$value->load("users.devicetech");
				 			$value['userData'] = $value['users']['devicetech'];
				 			unset($value['users']['devicetech']);
				 			break;
				 		case env("THIRD"):
				 			$value->load("users.thirdparty");
				 			$value['userData'] = $value['users']['thirdparty'];
				 			unset($value['users']['thirdparty']);
				 			break;
				 		case env("ASSOCIATION"):
				 			$value->load("users.association");
				 			$value['userData'] = $value['users']['association'];
				 			unset($value['users']['association']);
				 			break;
				 		case env("GOVERNMENT");
				 			$value->load("users.government");
				 			$value['userData'] = $value['users']['government'];
				 			unset($value['users']['government']);
				 			break;
				 	}
				 }

				 $recUsers = Users::where("is_rec", 1)->skip(($curPage - 1) * 5)->take(5)->get();
				 foreach($recUsers as $user){
				 	switch ($user["role_id"]) {
				 		case env("ENERGY"):
				 			$user->load("poweruser");
				 			break;
				 		case env("SAVER"):
				 			$user->load("energysaver");
				 			break;
				 		case env("DEVICE_TECH"):
				 			$user->load("devicetech");
				 			break;
				 		case env("THIRD"):
				 			$user->load("thirdparty");
				 			break;
				 		case env("ASSOCIATION"):
				 			$user->load("association");
				 			break;
				 		case env("GOVERNMENT");
				 			$user->load("government");
				 			break;
				 	}
				 }

				 $roles = UserRoles::whereNotIn("id", [0,1,8,9,10])->get()->toArray();

				 $bottomNumPerPage = 6;
				 $bottomProject = Projects::with(["projectDomain", "projectDomain.domain", "projectDomain.domain.parent", "projectTech", "projectTech.tech", "investmentType"])->where("is_rec", 1)->skip(($curPage - 1) * $bottomNumPerPage)->take(6)->get();
				 $bottomDevice = Devices::where("is_rec", 1)->skip(($curPage - 1) * $bottomNumPerPage)->take(6)->get();
				 $bottomTech = Technologies::where("is_rec", 1)->skip(($curPage - 1) * $bottomNumPerPage)->take(6)->get();

				 $queryStr = "";
				 foreach (Input::all() as $key => $value)
				 {
				 	$queryStr .= $key . "=" . $value . "&";
				 }
				 $params = ["users" => $temp, "count" => $count, "roles" => $roles, "recommand" => $recUsers, "bottomProject" => $bottomProject, "bottomDevice" => $bottomDevice, "bottomTech" => $bottomTech, "bottomTech" => $bottomTech, "curQuery" => $queryStr];

				 if(Input::has("gid")){
				 	$firstLevel = UserRoles::where("id", Input::get("gid"));
				 	if($firstLevel->count()){
				 		$params["firstLevel"] = $firstLevel->get()[0]["role_name"];
				 	}
				 }
				return view('user.search.group', $params)->withPresenter($presenter)->withIsGroup(true)->withIsIndustry(true);

				break;
		}



	}

	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create()
	{
		//
	}

	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store()
	{
		//
	}

	/**
	 * Display the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		//
	}

	/**
	 * Show the form for editing the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		//
	}

	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		//
	}

	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		//
	}

}
